exception NotInitialized
let v = function
  | Some(e) -> e
  | None -> raise NotInitialized

let s = function
  | Some(_) -> true
  | None -> false

class alldatas () =
object(self)
  val mutable labels = None
  val mutable labelsc = None
  val mutable mtrx_h = None
  val mutable mtrx_d = None
  val mutable dmtrx_call = None
  val mutable legend = None
  val mutable mapalts =None
  val mutable scale = 1.
  val mutable w = None
  val mutable h = None
  val mutable bbc = {Geometry.x = 0.; Geometry.y = 0.; Geometry.z = 0.}
  val mutable r = 0.

  method set_labels (l: int array array)
                    (lc: (int,(float*float*float))Hashtbl.t) =
    labels <- Some(l);
    labelsc <- Some(lc)


  method set_tesselmtrx (hm: (float * float) array array)
                 (dm: float array array) (wi:int) (he:int)
                 (dmtrxe: (((int*int*int)*float) list -> unit))
                 (legende: (((int*int*int) * float) list)) =
    mtrx_h <- Some(hm);
    mtrx_d <- Some(dm);
    w <- Some(wi);
    h <- Some(he);
    dmtrx_call <- Some(dmtrxe);
    legend <- Some(legende)
  method change_legend (legende: (((int*int*int) * float) list)) =
    legend <- Some(legende)

  method set_scale sc =
    scale <- sc;
    self#set_mapalts (v mapalts) scale

  method set_mapalts (m: float option array array) scale =
    let mz = ref max_float
    and mZ = ref (-.max_float)
    in
      for i = 0 to (v w) - 1 do
        for j = 0 to (v h) - 1 do
          let opt = m.(i).(j) in
            if (s opt) then
              if ((v opt) > !mZ) then
                mZ := (v opt)
              else
                if ((v opt) < !mz) then
                  mz := (v opt)
        done
      done;
      bbc.Geometry.x <- ((float_of_int (v w))*.scale)/.2.;
      bbc.Geometry.z <- ((float_of_int (v h))*.scale)/.2.;
      bbc.Geometry.y <- (!mz +. !mZ) /.2.;
      r <- (sqrt 2.)*.(Geometry.magnitude bbc);
      mapalts <- Some(m)

  method get_labels () =
    (v labels,v labelsc)
  method get_tesselmtrx () =
    (v mtrx_h,v mtrx_d,v w,v h,v dmtrx_call,v legend)
  method get_mapalts () =
    (v mapalts)
  method get_bsphere () =
    (r,bbc)

  method to_file (path:string) =
    ()
  method from_file (path:string) =
    ()
end
